package com.jp.knowledge.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.ExpData;
import com.jp.knowledge.util.ImageLoadUtil;

import java.util.List;

/**
 * Created by jiayen on 16/11/3.
 */

public   class CusAdaper extends BaseAdapter {

    private Context mContext;
    private List<ExpData.NewDataBean> list;
    public CusAdaper(List<ExpData.NewDataBean> list,Context context){
        this.mContext=context;
        this.list=list;

    }
    public void update(List<ExpData.NewDataBean> list){
        this.list=list;
        notifyDataSetChanged();
    }

    protected int getLayoutId() {
        return R.layout.com_text_layout;
    }

    protected void renderData(JPViewHolder holder, int position, ExpData.NewDataBean newDataBean) {
        ImageView img = holder.getView(R.id.icon);
        TextView name = holder.getView(R.id.name);
//        Glide.with(context).load(newDataBean.getIcon())
//                .fitCenter().placeholder(R.mipmap.toutiaoxiangqingmo)
//                .bitmapTransform(new RoundedCornersTransformation(context,15,3))
//                .into(img);
        ImageLoadUtil.loadrund(mContext,newDataBean.getIcon(),img,15);
        name.setText(newDataBean.getTitle());
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        JPViewHolder holder = JPViewHolder.get(mContext, getLayoutId(), parent, convertView);
        renderData(holder, position, list.get(position));
        return holder.getConvertView();
    }
}